/*
 * fixedsizerollingfilelogger.h
 *
 *  Created on: Jan 10, 2012
 *      Author: sihai
 */

#ifndef FIXEDSIZEROLLINGFILELOGGER_H_
#define FIXEDSIZEROLLINGFILELOGGER_H_

#include "log4cpp.h"

class FixedSizeRollingFileLogger : public Logger
{
	private:
			char* logfile;
			int fd;
			int index;
			int currentsize;
			int fixedsize;
			int buffersize;
			int position;
			char* buffer;
			pthread_mutex_t mutex;
	private:
			void log(const char* msg);
			void append(const char* msg);
			void _flush();
			bool is_need_change_log_file();
			bool change_log_file();
			void changed();
	public:
			FixedSizeRollingFileLogger(const char* logfile, int buffersize, int fixedsize = DEFAULT_FIXED_SIZE);
			~FixedSizeRollingFileLogger();
			bool init();
};

#endif /* FIXEDSIZEROLLINGFILELOGGER_H_ */
